﻿using AntaresShell.Logger;
using Repository.MODELs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Threading.Tasks;

namespace Repository.ServiceConnection.Controllers
{
    public class TaskLogController : BaseConnection
    {
        public TaskLogController()
        {
            ApiRoot += "TaskLog";
        }

        public async Task<dynamic> GetTaskLogsAsync(int id)
        {
            try
            {
                var resp = await HttpClient.GetAsync(new Uri(ApiRoot + @"/" + id));
                using (var stream = await resp.Content.ReadAsStreamAsync())
                {
                    var djs = new DataContractJsonSerializer(typeof(List<TaskLogModel>));
                    return new ObservableCollection<TaskLogModel>((IEnumerable<TaskLogModel>)djs.ReadObject(stream));
                }
            }
            catch (Exception ex)
            {
                LogManager.Instance.LogException(ex.ToString());
                return null;
            }
        }

        private static TaskLogController _instance;
        public static TaskLogController Instance
        {
            get { return _instance ?? (_instance = new TaskLogController()); }
        }
    }
}
